﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Insert : System.Web.UI.Page
{
    String strCon = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    String strCom;
    SqlConnection objCon;
    SqlCommand objCom;
    SqlDataReader dtReader;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        if (txtWName.Text == "" || txtWDescription.Text == "")
            lblStatus.Text = "กรอกข้อมูล";
        else
            InsertData();
    }
    protected void InsertData()
    {
        objCon = new SqlConnection(strCon);
        objCon.Open();
        strCom = "Insert Into Webboards (WOwner,WName,WDescription) " +
            " VALUES "
            + " ('" + Session["strUserID"]
            + "','" + txtWName.Text
            + "','" + txtWDescription.Text + "')";
        objCom = new SqlCommand(strCom, objCon);
        try
        {
            objCom.ExecuteNonQuery();
            Response.Redirect("Home.aspx");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}